package com.estar.integaration.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.estar.integaration.Mapper.CartMapper;
import com.estar.integaration.Service.ICartService;
import com.estar.integaration.entity.Cart;
import com.estar.integaration.entity.CartGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author YJL
 * @since 2021-11-18
 */
@Service
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements ICartService {

    @Autowired
    CartMapper cartMapper;

    /**
     * 根据userId查找到对应的cartId
     * @param cart
     * @return Cart
     *
     */
    @Override
    public void insert(Cart cart) {
        cartMapper.insert(cart);
    }

    @Override
    public Cart findCartByUserId(String userId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        return cartMapper.selectOne(queryWrapper);
    }

    @Override
    public List<CartGoods> selectList(QueryWrapper queryWrapper) {
        return cartMapper.selectList(queryWrapper);
    }

}
